/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-12
 * Time: 20:54
 */
class A<E extends Comparable<E>> {//要求传入的类必须实现了Comparable接口，下面用来数据之间的比较
    public E findMax(E[] array) {//利用compareTo进行比较，找到数组中的最大值
        int max = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[max].compareTo(array[i]) < 0) {
                max = i;
            }
        }
        return array[max];
        }
}
public class Student implements Comparable<Student>{//实现了Comparable接口
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override//重写compareTo方法，规范比较行为
    public int compareTo(Student o) {
        return this.age - o.age;
    }

    public static void main(String[] args) {
        Student[] students = new Student[]{
                new Student("dinsg",10),
                new Student("fdd",100),
                new Student("kasg",21),
                new Student("hau",1)
        };
        A<Student> aaa = new A<>();
        Student maxStudent = aaa.findMax(students);
        System.out.println(maxStudent);
    }
}
